package team.seekers.hula.question.questionDevelopBook.book.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import team.seekers.hula.question.questionDevelopBook.book.entity.dto.BookQueryDTO;
import team.seekers.hula.question.questionDevelopBook.book.entity.dto.BookUserRecordDTO;
import team.seekers.hula.question.questionDevelopBook.book.entity.vo.BookReadingInfoVO;
import team.seekers.hula.question.questionDevelopBook.book.entity.vo.BookReadingListVO;
import team.seekers.hula.common.annotation.ApiResponseBody;
import team.seekers.hula.common.entity.PageResult;
import team.seekers.hula.question.questionDevelopBook.book.service.BookUserService;
import team.seekers.hula.auth.service.MindUtils;

import java.util.List;

/**
 * <p>
 * 书籍 前端控制器
 * </p>
 *
 * @author hbc
 * @since 2022-11-22
 */
@Controller
@ApiResponseBody
@RequestMapping("/book/user")
public class BookUserController {

    @Autowired
    private BookUserService bookUserService;

//    @PostMapping("/add")
//    public R add(@RequestBody ModeAddDTO flomoVO){
//        String flomoId = flomoService.add(flomoVO);
//        // 返回mind
//        MindListVO mindListVO = mindService.getListVOByFlomoId(flomoId);
//        return R.success().data("mind",mindListVO);
//    }
//
//    @DeleteMapping("/delete/{FlomoId}")
//    public R delete(@PathVariable("FlomoId") String id){
//        if(ParamCheckUtils.isNotRightId(id)){
//            return R.fail(ResultCode.ACTION_FAIL);
//        }
//        boolean delete = flomoService.delete(id);
//        if(!delete){
//            return R.fail(ResultCode.ACTION_FAIL);
//        }
//        return R.success();
//    }
//
//

    @PostMapping("/record")
    public void update(@RequestBody BookUserRecordDTO recordDTO){
        recordDTO.setUserId(MindUtils.getUserId());
        bookUserService.record(recordDTO);
    }

    //
    @GetMapping("/info")
    public BookReadingInfoVO get(@RequestParam String id){
        return bookUserService.getBookReadingInfoVO(id,MindUtils.getUserId());
    }

    // 分页查询按照时间排序
    @GetMapping("/listAllMyBook")
    public List<BookReadingListVO> listAllMyBook(@RequestParam String name){
        return bookUserService.listAllMyBook(name,MindUtils.getUserId());
    }

    // 分页查询按照时间排序
    @GetMapping("/pageOrderByTime")
    public PageResult<BookReadingListVO> pageOrderByTime(@RequestParam BookQueryDTO queryDTO){
        queryDTO.setUserId(MindUtils.getUserId());
        return bookUserService.pageBookIdsOrderByTime(queryDTO);
    }

}

